
//
// 101214 - AH - (Hector) Created.
// 101219a- AH - MIXED.
// 101219b- AH - getPaint().
// 101219c- AH - Made InformationSource declared inside a top level type.
// 101219d- AH - Did away with InformationSource concept, this now have methods
//               to ask if got output from Mine, Forest or Network and methods
//               to get output from a specific source.
// 110327 - AH - Fixes related to get SpareWheel work in chat.
//

package org.soekrat.engine.rethor;

import java.io.CharArrayWriter;
import java.io.PrintWriter;
import java.util.List;

import org.soekrat.AttributeObject;
import org.soekrat.engine.forest.Forest;
import org.soekrat.engine.forest.Tree;
import org.soekrat.engine.mine.Mine;
import org.soekrat.engine.mine.Resource;
import org.soekrat.engine.network.Cluster;
import org.soekrat.engine.network.Network;

/**
 * <p>
 *   Answer from
 *   {@link Rethor#talk(java.util.List)}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
public final class RethorAnswer 
{
  private final List<AttributeObject> m_paint;
  
  private List<AttributeObject> m_resources=null;
  
  private List<AttributeObject> m_trees=null;
  
  private List<AttributeObject> m_clusters=null;
  
  private final String m_answer;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param answer Answer from
   *               {@link Rethor#talk(java.util.List)}.
   * @param paint  Retrieved.
   */
  RethorAnswer(String answer, List<AttributeObject> paint)
  {
    if (answer==null)
    {
      throw new NullPointerException("answer");
    }
    if (paint==null)
    {
      throw new NullPointerException("paint");
    }
    
    m_answer=answer;
    m_paint=paint;
  }
  
  /**
   * <p>
   *   Sets retrieved from the
   *   {@link Mine}.
   * </p>
   * @param resources {@link Resource}s, may be {@code null}.
   * @return {@code this}.
   */
  RethorAnswer setResources(List<AttributeObject> resources)
  {
    m_resources=resources;
    return this;
  }
  
  /**
   * <p>
   *   Sets retrieved from the
   *   {@link Forest}.
   * </p>
   * @param resources {@link Tree}s, may be {@code null}.
   * @return {@code this}.
   */
  RethorAnswer setTrees(List<AttributeObject> trees)
  {
    m_trees=trees;
    return this;
  }
  
  /**
   * <p>
   *   Sets retrieved from the
   *   {@link Network}.
   * </p>
   * @param clusters {@link Cluster}s, may be {@code null}.
   * @return {@code this}.
   */
  RethorAnswer setClusters(List<AttributeObject> clusters)
  {
    m_clusters=clusters;
    return this;
  }
  
  /**
   * <p>
   *   Gets answer from
   *   {@link Rethor#talk(java.util.List)}.
   * </p>
   * @return Answer.
   */
  public String getAnswer(){ return m_answer; }
  
  /**
   * <p>
   *   Gets retrieved.
   * </p>
   * @return Retrieved.
   */
  public List<AttributeObject> getPaint(){ return m_paint; }
  
  /**
   * <p>
   *   Gets retrieved from the
   *   {@link Mine}.
   * </p>
   * @return {@link Resource}s or {@code null} if nothing retrieved from the
   *         {@code Mine}.
   */
  public List<AttributeObject> getResources(){ return m_resources; }
  
  /**
   * <p>
   *   Gets retrieved from the
   *   {@link Forest}.
   * </p>
   * @return {@link Tree}s or {@code null} if nothing retrieved from the
   *         {@code Forest}.
   */
  public List<AttributeObject> getTrees(){ return m_trees; }
  
  /**
   * <p>
   *   Gets retrieved from the
   *   {@link Network}.
   * </p>
   * @return {@link Cluster}s or {@code null} if nothing retrieved from the
   *         {@code Network}.
   */
  public List<AttributeObject> getClusters(){ return m_clusters; }
  
  /**
   * <p>
   *   Tells if has output from the
   *   {@link Mine}.
   * </p>
   * @return {@code true} if has, {@code false} if has not.
   */
  public boolean hasMineOutput()
  { 
    return m_resources!=null && !m_resources.isEmpty(); 
  }
  
  /**
   * <p>
   *   Tells if has output from the
   *   {@link Forest}.
   * </p>
   * @return {@code true} if has, {@code false} if has not.
   */
  public boolean hasForestOutput()
  { 
    return m_trees!=null && !m_trees.isEmpty(); 
  }
  
  /**
   * <p>
   *   Tells if has output from the
   *   {@link Network}.
   * </p>
   * @return {@code true} if has, {@code false} if has not.
   */
  public boolean hasClusterOutput()
  { 
    return m_clusters!=null && !m_clusters.isEmpty(); 
  }
  
  @Override
  public String toString() 
  {
    CharArrayWriter caw=new CharArrayWriter();
	  PrintWriter pw=new PrintWriter(caw);
    
	  pw.println("answer: "+m_answer);
	  pw.println("paint: "+m_paint);
	
    pw.flush();
    return caw.toString();
  }
  
}
